package com.docker.drug.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.docker.common.annotation.Log;
import com.docker.common.core.controller.BaseController;
import com.docker.common.core.domain.AjaxResult;
import com.docker.common.enums.BusinessType;
import com.docker.drug.domain.DoctorDrugInventory;
import com.docker.drug.service.IDoctorDrugInventoryService;
import com.docker.common.utils.poi.ExcelUtil;
import com.docker.common.core.page.TableDataInfo;

/**
 * 药品盘点Controller
 * 
 * @author lin
 * @date 2025-04-15
 */
@RestController
@RequestMapping("/drug/inventory")
public class DoctorDrugInventoryController extends BaseController
{
    @Autowired
    private IDoctorDrugInventoryService doctorDrugInventoryService;

    /**
     * 查询药品盘点列表
     */
    @PreAuthorize("@ss.hasPermi('drug:inventory:list')")
    @GetMapping("/list")
    public TableDataInfo list(DoctorDrugInventory doctorDrugInventory)
    {
        startPage();
        List<DoctorDrugInventory> list = doctorDrugInventoryService.selectDoctorDrugInventoryList(doctorDrugInventory);
        return getDataTable(list);
    }

    /**
     * 导出药品盘点列表
     */
    @PreAuthorize("@ss.hasPermi('drug:inventory:export')")
    @Log(title = "药品盘点", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DoctorDrugInventory doctorDrugInventory)
    {
        List<DoctorDrugInventory> list = doctorDrugInventoryService.selectDoctorDrugInventoryList(doctorDrugInventory);
        ExcelUtil<DoctorDrugInventory> util = new ExcelUtil<DoctorDrugInventory>(DoctorDrugInventory.class);
        util.exportExcel(response, list, "药品盘点数据");
    }

    /**
     * 获取药品盘点详细信息
     */
    @PreAuthorize("@ss.hasPermi('drug:inventory:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(doctorDrugInventoryService.selectDoctorDrugInventoryById(id));
    }

    /**
     * 新增药品盘点
     */
    @PreAuthorize("@ss.hasPermi('drug:inventory:add')")
    @Log(title = "药品盘点", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DoctorDrugInventory doctorDrugInventory)
    {
        System.out.println(doctorDrugInventory);
        return toAjax(doctorDrugInventoryService.insertDoctorDrugInventory(doctorDrugInventory));
    }

    /**
     * 修改药品盘点
     */
    @PreAuthorize("@ss.hasPermi('drug:inventory:edit')")
    @Log(title = "药品盘点", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DoctorDrugInventory doctorDrugInventory)
    {
        return toAjax(doctorDrugInventoryService.updateDoctorDrugInventory(doctorDrugInventory));
    }

    /**
     * 删除药品盘点
     */
    @PreAuthorize("@ss.hasPermi('drug:inventory:remove')")
    @Log(title = "药品盘点", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(doctorDrugInventoryService.deleteDoctorDrugInventoryByIds(ids));
    }
}
